home *** CD-ROM | disk | FTP | other *** search
- /*
- MacPaint printing utility
- © 1992, S. Wilkerson
-
- written with THINK C 5.0
- */
-
- #include <PrintTraps.h>
-
- /* params */
-
- #define abtDialog 128
- #define alrtDialog 128
-
- enum {
- deskAcc = 1,
- file,
- edit,
- about = 1,
- pagesetup = 1,
- print,
- quit = 4,
- undo = 1,
- cut = 3,
- copy,
- paste,
- clear
- };
-
- MenuHandle deskAccM, fileM, editM, viewM;
- THPrint hPrint;
-
- main()
- {
- Boolean notDone = true, DoMenus();
- EventRecord event;
- WindowPtr whichWindow;
-
- Init();
- FlushEvents( everyEvent, 0 );
- while( notDone ) {
- if ( WaitNextEvent( everyEvent, &event, 60L, NIL ) ) {
- switch ( event.what ) {
-
- case osEvt:
- /* !! need to check this out */
- break;
-
- case mouseDown:
- switch( FindWindow( event.where, &whichWindow ) ) {
-
- case inMenuBar:
- notDone = DoMenus( MenuSelect( event.where ) );
- break;
-
- case inSysWindow:
- SystemClick( &event, whichWindow );
- break;
-
- default:
- break;
- }
- break;
-
- case keyDown:
- case autoKey:
- if ( event.modifiers & cmdKey )
- notDone = DoMenus( MenuKey( (char)event.message ) );
- break;
-
- default:
- break;
- }
- }
- }
- Cleanup();
-
- } /* main */
-
- Boolean DoMenus( select )
- long select;
- {
- short menuID, menuItem;
- Boolean result = true;
- Str255 theAcc;
-
- menuItem = LoWord( select );
- switch( menuID = HiWord( select ) ) {
-
- case deskAcc:
- if ( menuItem == about )
- OpenAbout();
- else {
- GetItem( deskAccM, menuItem, theAcc );
- OpenDeskAcc( theAcc );
- }
- break;
-
- case file:
- switch( menuItem ) {
-
- case pagesetup:
- PrStlDialog( hPrint );
- break;
-
- case print:
- PrintMacPaintFile();
- break;
-
- case quit:
- result = false;
- break;
-
- default:
- break;
- }
- break;
-
- case edit:
- SystemEdit( menuItem - 1 );
- break;
-
- default:
- break;
- }
- HiliteMenu( 0 );
- return( result );
-
- } /* DoMenus */
-
- pascal void myItem( theDialog, itemNo )
- DialogPtr theDialog;
- short itemNo;
- {
- short itemType;
- Handle item;
- Rect displayRect;
-
- GetDItem( theDialog, itemNo, &itemType, &item, &displayRect );
- PenSize( 3, 3 );
- InsetRect( &displayRect, -4, -4 );
- FrameRoundRect( &displayRect, 16, 16 );
- PenNormal();
-
- } /* myItem */
-
- OpenAbout()
- {
- DialogPtr theDialog;
- short itemHit = 0, itemType;
- Handle item;
- Rect box;
- pascal void myItem();
-
- theDialog = GetNewDialog( abtDialog, NIL, (WindowPtr)-1 );
- GetDItem( theDialog, OK, &itemType, &item, &box );
- SetDItem( theDialog, OK + 1, userItem, (Handle)myItem, &box );
- while ( !itemHit )
- ModalDialog( NIL, &itemHit );
- DisposDialog( theDialog );
-
- } /* OpenAbout */
-
- Boolean GetFile( fileName, vRefNum, numTypes, reqTypes )
- char *fileName;
- short *vRefNum, numTypes;
- SFTypeList reqTypes;
- {
- short i;
- Point TopLeft;
- SFTypeList typeList;
- SFReply reply;
-
- SetPt( &TopLeft, 80, 90 );
- SFGetFile( TopLeft, "\p", 0L, numTypes, reqTypes, 0L, &reply );
- if ( reply.good ) {
- for ( i = 0; i <= reply.fName[0]; i++ )
- fileName[i] = reply.fName[i];
- *vRefNum = reply.vRefNum;
- return ( true );
- }
- else
- return ( false );
-
- } /* GetFile */
-
- PrintMacPaintFile()
- {
- Str255 fileName;
- short vRefNum, refNum;
- long reqTypes = 'PNTG';
- Rect theRect;
- WindowPtr theTempWindow;
- TPPrPort pPrPort;
- TPPrint pPrint;
- TPrStatus prStatus;
- Boolean spoolNeeded, GetFile();
-
- if ( GetFile( fileName, &vRefNum, 1, &reqTypes ) ) {
- if ( FSOpen( fileName, vRefNum, &refNum ) == noErr ) {
- if ( PrJobDialog( hPrint ) && ( PrError() == noErr ) ) {
- SetCursor( *GetCursor( watchCursor ) );
- SetRect( &theRect, 1, 1, 2, 2 );
- theTempWindow = NewWindow( NIL, &theRect, fileName, true,
- plainDBox, (WindowPtr)-1L, false, 1L );
- PrValidate( hPrint );
- pPrPort = PrOpenDoc( hPrint, NIL, NIL );
- PrOpenPage( pPrPort, NIL );
- DrawMacPaintFile( refNum );
- PrClosePage( pPrPort );
- PrCloseDoc( pPrPort );
- HLock( hPrint );
- pPrint = *hPrint;
- spoolNeeded = ( pPrint->prJob.bJDocLoop == bSpoolLoop );
- HUnlock( hPrint );
- if ( spoolNeeded && ( PrError() == noErr ) )
- PrPicFile( hPrint, NIL, NIL, NIL, &prStatus );
- DisposeWindow( theTempWindow );
- InitCursor();
- }
- }
- else {
- StopAlert( alrtDialog, NIL );
- }
- FSClose( refNum );
- }
-
- } /* PrintMacPaintFile */
-
- DrawMacPaintFile( refNum )
- short refNum;
- {
- short i;
- long logEOF;
- Ptr srcPtr, dstPtr;
- BitMap theBitMap;
- Rect theRect;
-
- GetEOF( refNum, &logEOF );
- logEOF -= 512L;
- SetFPos( refNum, fsFromStart, 512L );
- srcPtr = NewPtr( logEOF );
- FSRead( refNum, &logEOF, srcPtr );
- theBitMap.baseAddr = NewPtr( 72L );
- theBitMap.rowBytes = 72;
- SetRect( &(theBitMap.bounds), 0, 0, 576, 1 );
- SetRect( &theRect, 0, 0, 576, 1 );
- for ( i = 0; i < 720; i++ ) {
- dstPtr = theBitMap.baseAddr;
- UnpackBits( &srcPtr, &dstPtr, 72 );
- CopyBits( &theBitMap, &(thePort->portBits), &(theBitMap.bounds),
- &theRect, srcCopy, NIL );
- OffsetRect( &theRect, 0, 1 );
- }
- DisposPtr( theBitMap.baseAddr );
- DisposPtr( srcPtr );
-
- } /* DrawMacPaintFile */
-
- Cleanup()
- {
- DisposeHandle( hPrint );
- PrClose();
-
- } /* Cleanup */
-
- Init()
- {
- Rect theRect;
- char apple[2];
-
- /* managers */
-
- InitGraf( &thePort );
- InitFonts();
- InitWindows();
- InitDialogs( NIL );
- InitMenus();
- MaxApplZone();
-
- /* menus */
-
- apple[0] = 1; apple[1] = 0x14;
- deskAccM = NewMenu( deskAcc, apple );
- AppendMenu( deskAccM, "\pAbout this thing…;-(" );
- AddResMenu( deskAccM, 'DRVR' );
- InsertMenu( deskAccM, 0 );
- fileM = NewMenu( file, "\pFile" );
- AppendMenu( fileM, "\pPage Setup…;Print…/P;-(;Quit/Q" );
- InsertMenu( fileM, 0 );
- editM = NewMenu( edit, "\pEdit" );
- AppendMenu( editM, "\pUndo/Z;-(;Cut/X;Copy/C;Paste/V;Clear" );
- InsertMenu( editM, 0 );
- DrawMenuBar();
-
- /* misc */
-
- PrOpen();
- hPrint = (THPrint)NewHandle( sizeof( TPrint ) );
- PrintDefault( hPrint );
- InitCursor();
-
- } /* Init */
-